home *** CD-ROM | disk | FTP | other *** search
/ Trading on the Edge / Trading On The Edge - CD-ROM Toolkit (Wayzata Technology)(2031)(1994).bin / pc / mac_file / vendor_d / neuralwa / nw2v50 / modnn.ind < prev    next >
File List  |  1993-08-23  |  12KB  |  520 lines

  1. inst4.1
  2. !****************************************************************
  3. !*                                *
  4. !*    Modular Neural Network Generator            *
  5. !*                                *
  6. !*    &In     Number of Input nodes                *
  7. !*    &Hd1    Number of Hidden PEs in Local Expert        *
  8. !*    &Out    Number of Output nodes                *
  9. !*    GNNO    Number of Local Experts                *
  10. !*    GNNH    Number of Hidden PEs in Gating network        *
  11. !*                                *
  12. !****************************************************************
  13.  
  14. ! Modular Hierarchical Neural Network
  15. !
  16. ?&In    1
  17. >bge    CheckHd1
  18. @Err    "Modular Neural Network MUST have at least one input PE"
  19. :CheckHd1
  20. ?GNNO    2
  21. >bge    CheckOut
  22. @Err    "Modular Neural Network MUST have at least two local experts"
  23. :CheckOut
  24. ?BPAa    0            !check for auto-associative
  25. >beq    Hetero1
  26. =&Out    &In
  27. >br    OutOK
  28. :Hetero1            !hetero-associative
  29. ?&Out    1
  30. >bge    OutOK
  31. @Err    "Modular Neural Network MUST have at least one output PE"
  32. :OutOK
  33.  
  34. @LdCS    "modnn"            !standard control strategy
  35.  
  36. !Load fixed schedules for DBD and EDBD.
  37. ?BPLf    "Delta-Bar-Delta"    !DBD?
  38. >bne    NotDBD1            !Branch to next test if not
  39. @LdLR    "dbd"            !Load default dbd schedule
  40. =GrLF    "mnndbd"        !instrument list file
  41. >br    LRS1            !Continue
  42. :NotDBD1
  43. ?BPLf    "Ext DBD"        !EDBD
  44. >bne    NotEDBD1        !Branch if not
  45. @LdLR    "edbd"            !Load default edbd schedule
  46. =GrLF    "mnnedbd"        !instrument list file
  47. >br    LRS1
  48. :NotEDBD1
  49. @LdLR    "backprop"        !Load default backprop schedule
  50. =GrLF    "mnnbackp"        !instrument list file
  51. :LRS1
  52.  
  53. =netn "Untitled"
  54. =DLnF    0            !learn  re-display off
  55. =DRcF    0            !recall re-display off
  56.  
  57. !    *** Build the Input Layer ***
  58.  
  59. @LLdf                !load default layer to menu area
  60. =LDln    "In"            !layer name
  61. =Lpes    &In            !copy # of input PEs from menu
  62. =Ltrn    "Linear"        !buffer
  63. ?BPGN    0            !Gaussian Init?
  64. >beq    GN1            !No
  65. =Lnse    "Gaussian"        !Yes
  66. :GN1
  67. =x    100            !place to put layer on screen
  68. =y     50
  69. #Incl    "stdnwgtf.iif"        !standard # weight fields
  70. @LAdd                !add the input layer
  71.  
  72. !    *** Build the Projection Layer if requested ***
  73.  
  74. ?BPPL    0            !Projection layer requested?
  75. >beq    ProjL1            !No
  76.  
  77. #Incl   "proj_lyr.iif"
  78.  
  79. :ProjL1
  80.  
  81. =n6    LayN            !Effective "Input layer"
  82. =n5    Lpes            !#processing elements
  83.  
  84. ! Try to calculate reasonable spacing. Store in n7
  85. =n7    50            !Layer spacing
  86. =n0    &Hd1
  87. ?&Hd1    &Out
  88. >bgt    HdGTOut
  89. =n0    &Out
  90. :HdGTOut
  91.  
  92. *n7    n0
  93. +n7    100
  94.  
  95. ! Build Gating network Hidden layer
  96. =n2    n5            !Num PEs in prev layer
  97. =n3    n6            !"Hidden" layer number
  98. +y    50            !up higher on display
  99.  
  100. ?GNNH    1
  101. >blt    NoGatHd1        !No gating network output layer
  102.  
  103. @LLdf                !start with default layer again
  104. =LDln    "GateHid"        !layer name
  105. =Lpes    GNNH            !Number of PEs
  106. =LDsh   1            !Make this triangular
  107. ?BPTf    "DNNA"            !Check for DNNA
  108. >bne    DNNAGH
  109. =Lsum    "DNNA"            !DNNA summation
  110. :DNNAGH
  111. =Ltrn    BPTf            !Transfer function
  112. =Llrn    BPLf            !Learning Rule
  113. ?BPGN    0            !Gaussian Init?
  114. >beq    GNGH            !No
  115. =Lnse    "Gaussian"        !Yes
  116. :GNGH
  117. =Lerf    "standard"
  118. !Use net global schedules for DBD and EDBD.  Create
  119. !schedules for others
  120. ?BPLf    "Delta-Bar-Delta"    !DBD?
  121. >beq    LRSGH            !If yes, use net global
  122. ?BPLf    "Ext DBD"        !EDBD?
  123. >beq    LRSGH            !If yes, use net global
  124. =BBLC    GHLC            !Gating hidden Learn Coef
  125. @NLRS    LDln
  126. #Incl    "bkpsched.iif"        !corrupts n0,n1,f0,f1,f2
  127. =Llrs    LDln            !Point to it
  128. :LRSGH
  129. =f0    n2            !# PEs in "input" layer
  130. #Incl    "wghtinit.iif"
  131. =LInH    f1
  132. =LInL    0.0
  133. -LInL    LInH            !-ve of high init limit
  134. =LFPO    FPOf            !F' Offset
  135. #Incl    "stdnwgtf.iif"        !standard # weight fields
  136. @LAdd
  137. =n3    LayN            !Remember layer number
  138.  
  139. :NoGatHd1
  140.  
  141. +y    50            !up higher on display
  142.  
  143. ! Build Gating Network Output Layer
  144. @LLdf                !start with default layer again
  145. =LDln    "GateOut"        !layer name
  146. =Lpes    GNNO            !Number of PEs
  147. =LDsh   1            !Make this triangular
  148. =Ltrn    "Linear"        !Exponential transfer function
  149. =Lcmp    "SoftMax"        !SoftMax activation
  150. =Llrn    BPLf            !Learning Rule
  151. ?BPGN    0            !Gaussian Init?
  152. >beq    GNGO            !No
  153. =Lnse    "Gaussian"        !Yes
  154. :GNGO
  155. !Use net global schedules for DBD and EDBD.  Create
  156. !schedules for others
  157. ?BPLf    "Delta-Bar-Delta"    !DBD?
  158. >beq    LRSGO            !If yes, use net global
  159. ?BPLf    "Ext DBD"        !EDBD?
  160. >beq    LRSGO            !If yes, use net global
  161. =BBLC    GOLC            !Gating Output Learn Coef
  162. @NLRS    LDln
  163. #Incl    "bkpsched.iif"        !corrupts n0,n1,f0,f1,f2
  164. =Llrs    LDln            !Point to it
  165. :LRSGO
  166. =f0    n2            !# PEs in previous layer
  167. #Incl    "wghtinit.iif"
  168. =LInH    f1
  169. =LInL    0.0
  170. -LInL    LInH            !-ve of high init limit
  171. =LFPO    FPOf            !F' Offset
  172. =n2    Lpes            !#processing elements
  173. #Incl    "stdnwgtf.iif"        !standard # weight fields
  174. @LAdd
  175.  
  176. !Now put in the Connections
  177. =n1    LayN
  178. =cnwt    1.0            !connection weight
  179. =cnty    WVar            !Variable
  180. =cnsc    WRel            !Relative
  181.  
  182. =SPEl    n1            !Destination layer
  183. @SlPE
  184. =NPEl    -1            !Bias layer
  185. @NrPE
  186. @LCFl                !full connections
  187.  
  188. =NPEl    n3            !Source (previous) layer
  189. @NrPE
  190. @LCFl                !full connections
  191.  
  192. ?n3    n6            !Compare input and hidden layer nums
  193. >beq    NoGatHd2        !skip if same
  194.  
  195. =NPEl    n6            !"Input" layer
  196. @NrPE
  197.  
  198. ?BPCP    0            !connect prior layers?
  199. >beq    GNoPrior        !skip if not
  200. @LCFl                !full connections
  201.  
  202. :GNoPrior
  203. =SPEl    n3            !Destination layer
  204. @SlPE
  205. @LCFl                !full connections
  206.  
  207. =NPEl    -1            !Bias layer
  208. @NrPE
  209. @LCFl                !full connections
  210.  
  211. :NoGatHd2
  212.  
  213. ! Build Local Expert Hidden layer
  214. =n4    0            !Local expert index
  215. :LocExp
  216. +n4    1            !Increment counter
  217. -y    50            !Down to hidden level
  218. +x    n7            !across
  219. =n2    n5            !Num PEs in prev layer
  220. =n3    n6            !"Hidden" layer number
  221.  
  222. ?&Hd1    1
  223. >blt    NoExpHd1        !No local expert hidden layer
  224. @LLdf                !start with default layer
  225. =LDln    "ExpHid"        !layer name
  226. +LDln    n4            !index the name
  227. =Lpes    &Hd1            !Number of PEs
  228. ?BPTf    "DNNA"            !Check for DNNA
  229. >bne    DNNAEH
  230. =Lsum    "DNNA"            !DNNA summation
  231. :DNNAEH
  232. =Ltrn    BPTf            !Transfer function
  233. =Llrn    BPLf            !Learning Rule
  234. ?BPGN    0            !Gaussian Init?
  235. >beq    GNEH            !No
  236. =Lnse    "Gaussian"        !Yes
  237. :GNEH
  238. =Lerf    "standard"
  239. !Use net global schedules for DBD and EDBD.  Create
  240. !schedules for others
  241. ?BPLf    "Delta-Bar-Delta"    !DBD?
  242. >beq    LRSEH            !If yes, use net global
  243. ?BPLf    "Ext DBD"        !EDBD?
  244. >beq    LRSEH            !If yes, use net global
  245. ?n4    1            !Only create sched first time
  246. >bgt    DontCrH
  247. =BBLC    H1LC            !Hidden 1 learning coef.
  248. @NLRS    "ExpHid"
  249. #Incl bkpsched.iif        !corrupts n0,n1,f0,f1,f2
  250. :DontCrH
  251. =Llrs    "ExpHid"        !Point to it
  252. :LRSEH
  253. =f0    n2            !# PEs in "input" layer
  254. #Incl    "wghtinit.iif"
  255. =LInH    f1
  256. =LInL    0.0
  257. -LInL    LInH            !-ve of high init limit
  258. =LFPO    FPOf            !F' Offset
  259. #Incl    "stdnwgtf.iif"        !standard # weight fields
  260. @LAdd
  261.  
  262. :NoExpHd1
  263.  
  264. +y    50            !up higher on display
  265. ! Build Local Expert Output Layer
  266. @LLdf                !start with default layer again
  267. =LDln    "ExpOut"        !layer name
  268. +LDln    n4            !index the name
  269. =Lpes    &Out            !Number of PEs
  270. ?BPTf    "DNNA"            !Check for DNNA
  271. >bne    DNNAEO
  272. =Lsum    "DNNA"            !DNNA summation
  273. =Ltrn    "DNNA"            !DNNA transfer
  274. >br    NoLinEO            !Don't use Linear Output for DNNA
  275. :DNNAEO
  276. =Ltrn    BPTf            !Transfer function
  277. ?BPLi    0            !Linear Output?
  278. >beq    NoLinEO            !Branch if not
  279. =Ltrn    "Linear"
  280. :NoLinEO
  281. =Llrn    BPLf            !Learning Rule
  282. ?BPGN    0            !Gaussian Init?
  283. >beq    GNEO            !No
  284. =Lnse    "Gaussian"        !Yes
  285. :GNEO
  286. !Use net global schedules for DBD and EDBD.  Create
  287. !schedules for others
  288. ?BPLf    "Delta-Bar-Delta"    !DBD?
  289. >beq    LRSEO            !If yes, use net global
  290. ?BPLf    "Ext DBD"        !EDBD?
  291. >beq    LRSEO            !If yes, use net global
  292. ?n4    1            !Only create sched first time
  293. >bgt    DontCrO
  294. =BBLC    OPLC            !output learning coef.
  295. @NLRS    "ExpOut"
  296. #Incl bkpsched.iif        !corrupts n0,n1,f0,f1,f2
  297. :DontCrO
  298. =Llrs    "ExpOut"        !Point to it
  299. :LRSEO
  300. =f0    n2            !# PEs in previous layer
  301. #Incl    "wghtinit.iif"
  302. =LInH    f1
  303. =LInL    0.0
  304. -LInL    LInH            !-ve of high init limit
  305. =LFPO    FPOf            !F' Offset
  306. =n2    Lpes            !#processing elements
  307. #Incl    "stdnwgtf.iif"        !standard # weight fields
  308. @LAdd
  309.  
  310. !Now put in the Connections
  311. =n1    LayN
  312. =cnwt    1.0            !connection weight
  313. =cnty    WVar            !Variable
  314. =cnsc    WRel            !Relative
  315.  
  316. ?&Hd1    1
  317. >blt    NoExpHd2        !No local expert hidden layer
  318.  
  319. =n3    n1
  320. -n3    n4            !subtract off output layers
  321. -n3    1            !subtract off gating output layer
  322. =SPEl    n3            !Destination layer
  323. @SlPE
  324. =NPEl    -1            !Bias layer
  325. @NrPE
  326. @LCFl                !full connections
  327.  
  328. =NPEl    n6            !Source layer (input layer)
  329. @NrPE
  330. @LCFl                !full connections
  331.  
  332. ?BPCP    0            !connect prior layers?
  333. >beq    NoExpHd2        !skip if not
  334. =SPEl    n1            !Destination layer
  335. @SlPE
  336. @LCFl                !full connections
  337.  
  338. :NoExpHd2
  339. =SPEl    n1            !Destination layer
  340. @SlPE
  341.  
  342. =NPEl    n3            !Source layer
  343. @NrPE
  344. @LCFl                !full connections
  345.  
  346. =NPEl    -1            !Bias layer
  347. @NrPE
  348. @LCFl                !full connections
  349.  
  350. !Loop if there are more experts
  351. ?n4    GNNO
  352. >blt    LocExp            !Do next local expert
  353.  
  354. ! Now build gating layer
  355. @LLdf                !start with default layer again
  356. =x    100
  357. +y    50
  358. =LDln    "Gate"            !layer name
  359. =Lpes    &Out            !Number of PEs
  360. +Lpes    1
  361. *Lpes    GNNO
  362. =n5    Lpes
  363. =LDsh   2            !Make this circular
  364. =Lcmp    "ModNNGate"
  365. =Lerf    "ModNNGate"
  366. #Incl    "stdnwgtf.iif"        !standard # weight fields
  367. @LAdd
  368.  
  369. ! Connect up gating network to gate layer
  370. =SPEl    LayN            !Destination layer
  371. =NPEl    LayN
  372. -NPEl    GNNO
  373. -NPEl    1
  374. =cnsc    WRel
  375. =cnty    WFix
  376. =cnwt    1.0
  377. @LCCr                !Connect correspondingly
  378.  
  379. ! Connect up local experts to gate layer
  380.  
  381. =SPEn    GNNO
  382. =n4    0            !Count # experts
  383.  
  384. :GateLoop
  385. +n4    1
  386. +NPEl    1            !Source layer
  387. =NPEn    0            !Start at the beginning
  388.  
  389. :InLoop
  390. @NrPE                !Select Source PE
  391. @SlPE                !Select Destination PE
  392. @PCon                !connect two PEs together
  393. +NPEn    1            !next PE in source
  394. +SPEn    1            !next PE in dest.
  395. ?NPEn    &Out            !Source PE off the end?
  396. >blt    InLoop            !No
  397.  
  398. ?n4    GNNO
  399. >blt    GateLoop
  400.  
  401. ! Now build output layer
  402. @LLdf                !start with default layer again
  403. =x    100
  404. +x    n7
  405. +y    60
  406. =LDln    "Output"        !layer name
  407. =Lpes    &Out            !Number of PEs
  408. #Incl    "stdnwgtf.iif"        !standard # weight fields
  409. @LAdd
  410.  
  411. !    *** Connect the gating layer to the output layer: Setup ***
  412.  
  413. =SPEl    LayN            !destination layer
  414. =NPEl    LayN
  415. -NPEl    1            !source layer
  416. =SPEn    0
  417. =NPEn    GNNO
  418. =cnwt    1.0            !set weight to 1.0
  419. =cnty    WFix            !fixed weight
  420. =cnsc    WRel            !relative connections
  421.  
  422. !    *** Connect the gating layer to the output layer ***
  423.  
  424. :OutCn
  425. @SlPE                !select next PE in output layer
  426. @NrPE                !select next PE in gate layer
  427. @PCon                !connect two PEs together
  428. +SPEn    1            !next PE in output layer
  429. ?SPEn    &Out            !past the end?
  430. >blt    OutPEOK
  431. =SPEn    0            !back to start of output layer
  432. :OutPEOK
  433. +NPEn    1            !next PE in the competitive layer
  434. ?NPEn    n5            !done with layer?
  435. >blt    OutCn            !no, keep going
  436.  
  437.  
  438. ! Check-pointing
  439. =LnPr    0            !no pruning
  440. ?BPTf    "DNNA"
  441. >bne    DNNA3
  442. =DLnN    1            !learn count for Check Points
  443. =MWLF    1            !turn on weight limiting
  444. =WtVl    0.99            !max value for weight limiting
  445. :DNNA3
  446.  
  447. !    *** Select Control Strategy & L/R Schedule ***
  448.  
  449. @LLsl                !load super layer
  450. =Lctl    "modnn"            !control strategy
  451.  
  452. !Use default fixed schedules for DBD and EDBD.
  453. ?BPLf    "Delta-Bar-Delta"    !DBD?
  454. >bne    NotDBD2            !Branch to next test if not
  455. =Llrs    "dbd"            !Fixed schedule
  456. >br    LRSDef            !Continue
  457. :NotDBD2
  458. ?BPLf    "Ext DBD"        !EDBD
  459. >bne    NotEDBD2        !Branch if not
  460. =Llrs    "edbd"            !Fixed schedule
  461. >br    LRSDef            !continue
  462. :NotEDBD2
  463. =Llrs    "backprop"        !backprop L/R Schedule
  464. :LRSDef
  465. !
  466. ! I/O parameters:
  467. !
  468. =Llnn    "train"            !name of learn input
  469. =Lrcn    "test"            !name of recall output
  470. #Incl    "stdioset.iif"        !standard I/O settings
  471. =Lax1    Epch            !set epoch from dialog
  472. ?BPAa    0            !check for auto-associative
  473. >beq    Hetero2
  474. +Lflg    LAAs            !auto-associative network
  475. :Hetero2
  476. ! Target ranges for MinMax tables
  477. =Lscl    0.0            !input  low-value
  478. ?BPIn   0            !Bipolar Inputs
  479. >beq    UnipInp            !branch if unipolar
  480. =Lscl    -1.0            !input  low-value
  481. :UnipInp
  482. =Loff    1.0            !input  high-value
  483. =Llow    0.2            !output low-value
  484. =Lhgh    0.8            !output high-value
  485. ?BPTf    "DNNA"            !DNNA?
  486. >beq    UniPolar        !Yes (Linear output not allowed)
  487. ?BPLi    0            !Linear Output?
  488. >bne    BiPolar            !If yes, bipolar
  489. ?BPTf    "Sigmoid"        !Sigmoid?
  490. >beq    UniPolar        !Yes
  491. ?BPTf    "Perceptron"        !Perceptron?
  492. >beq    UniPolar        !Yes
  493. ?BPTf    "StepFunction"        !Step function?
  494. >beq    UniPolar        !Yes
  495. :BiPolar
  496. =Lscl     -1.0            !input  low-value
  497. =Llow     -0.8            !output low-value
  498. :UniPolar
  499. @SVsl                !save it back
  500. !
  501. ! Miscellaneous globals
  502. =Grph     1            !Activate instrument list
  503. =jogl    -.1            !lower limit for jog
  504. =jogh    +.1            !upper limit for jog
  505. =seed    257            !starting seed number
  506. @seed                !set the seed
  507. !
  508. ! Recall/Test modes
  509. =RnTm    1
  510. =RnRm    1
  511. !set to learn for 50000
  512. =RnLm    0
  513. =LrnN    50000
  514. !
  515. ! Initialize the network
  516. !
  517. @Nini
  518. @EOF
  519.  
  520.